﻿//创建人：longb
//日期：2022-04-25
//描述：日历维护HTML页面
var page = {
    pagetotal: 0,
    pageSize: 20,
    pageNumber: 1,
    editIndex: null, //easyUI单元格编辑
    rootPath: getRootPath(), //网站根路径
    ajaxUrl: getRootPath() + "/Ashx/ZsHandler/ZSProcessHandler.ashx",
    //初始化页面
    init: function () {
        page.bind();
        customizedEasyuiPagination('pp'); //定制化分页
    },
    //页面事件绑定
    bind: function () {
        $('#OrderType').combobox({
            data: [{ id: 1, text: '正常' }, { id: 0, text: '临时'}],
            valueField: 'id',
            textField: 'text'
        });
        $('#PsType').combobox({
            data: [{ id: 0, text: '否' }, { id: 1, text: '是'}],
            valueField: 'id',
            textField: 'text'
        });
        $('#OrderType').combobox("setValue", 1);
        $('#PsType').combobox("setValue", 1);
        //任务单信息
        $('#OrderTabel').datagrid({
            columns: [[
                { field: 'code1', title: '选择', width: 100, checkbox: true },
		        { field: 'ATTRIBUTEVALUE', title: '发动机号', width: 120 },
                 { field: 'MFGORDERNAME', title: '订单号', width: 150 },
		         { field: 'TOGETHERFLAG', title: '任务单号', width: 180 },
		         { field: 'WORKFLOWTYPE', title: '任务类型', width: 130 }, //--
                 {field: 'PRODUCTNAME', title: '件号', width: 120 },
                 { field: 'DESCRIPTION', title: '件号名称', width: 90 },
                 { field: 'WFDESC', title: '工艺名称', width: 120 },
                 { field: 'PLANNEDSTARTDATE', title: '计划开始时间', width: 130, formatter: function (value, row, index) {
                     if (value != null)
                         return dayjs(value).format("YYYY-MM-DD");
                 }
                 },
                 { field: 'PLANNEDCOMPLETIONDATE', title: '计划完成时间', width: 130, formatter: function (value, row, index) {
                     if (value != null)
                         return dayjs(value).format("YYYY-MM-DD");
                 }
                 },
                 { field: 'STATUS', title: '任务状态', width: 100, styler: function (value, row, index) { if (value == "待接收") { return 'color:red'; } else { return 'color:#99e4ff'; } } },
                 { field: 'WORKFLOWSTEPNAME', title: '阶段', width: 100 }
                ]],
            onLoadSuccess: function (data) {
                $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                    total: page.pagetotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
                customizedEasyuiPagination('pp'); //定制化分页
            }
        });

        //分页事件
        $('#pp').pagination({
            onSelectPage: function (pageNumber, pageSize) {
                customizedEasyuiPagination('pp'); //定制化分页
                page.pageSize = pageSize; page.pageNumber = pageNumber;
                page.GetTaskOrderData();
            }
        });
        //绑定分页go按钮
        $('#pageGo').on("click", function () {
            var pageNumber = $(this).parents('tr').find('.pagination-num').val();
            page.pageNumber = pageNumber;
            page.GetTaskOrderData();
        });
    },
    //查询
    searchData: function () {
        page.reset(false, true);
        page.pageNumber = 1;
        page.GetTaskOrderData();
    },
    //查询任务单信息
    GetTaskOrderData: function () {
        var frdata = $('#searchForm').serializeArray();
        var data = {};
        $.each(frdata, function () {
            data[this.name] = this.value
        });
        var param = {
            action: "GetTaskOrderData",
            pageSize: page.pageSize,
            pageNumber: page.pageNumber,
            data: JSON.stringify([data])
        };
        page.post(param, function (res) {
            if (res.Result) {
                //console.info(res);
                page.pagetotal = res.RowCount;
                $('#OrderTabel').datagrid('loadData', res.DBTable);
            }
        });
    },
    //任务接收
    TaskRecive: function () {
        page.UpdateProcessTaskOrderStatus("1");
    },
    //准备完成
    ReadyToFinish: function () {
        page.UpdateProcessTaskOrderStatus("2");
    },
    UpdateProcessTaskOrderStatus: function (status) {
        var rows = $('#OrderTabel').datagrid("getChecked");
        if (rows.length == 0) { displayMessage("请先勾选数据再进行操作", false); return; }
        var ids = [];
        $.each(rows, function (index, item) {
            if (item.STATUS == "待接收" && status == "1") {
                ids.push(item.ENGINEPARTPLANID);
            }
            if (item.STATUS == "准备中" && status == "2") {
                ids.push(item.ENGINEPARTPLANID);
            }
        });
        if (status == "1" && ids.length == 0) { displayMessage("请先勾选[待接收]数据再进行操作", false); return; }
        if (status == "2" && ids.length == 0) { displayMessage("请先勾选[准备中]数据再进行操作", false); return; }
        var param = {
            action: "UpdateProcessTaskOrderStatus",
            status: status,
            ids: ids.join(',')
        };
        page.post(param, function (res) {
            if (res.Result) {
                page.GetTaskOrderData();
            }
            displayMessage(res.Message, res.Result);
        });
    },
    //查询重置
    searchReset: function () {
        $('#searchForm').form('clear');
        customizedEasyuiPagination('pp'); //定制化分页
    },
    //清除方法，重要！！！
    reset: function (iscondition, isresult) {
        clearMessage();
    },
    //post数据
    post: function (param, callback) {
        $.ajax({
            type: "Post",
            url: page.ajaxUrl,
            data: param,
            cashe: false,
            async: true,
            dataType: "json",
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                $.messager.progress('close');
                callback(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                displayMessage(XMLHttpRequest.responseText, false);
            }
        });
    }
}
$(function () {
    page.init();
});